package com.taotao.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.taotao.mapper.TbContentCategoryMapper;
import com.taotao.pojo.TaotaoResult;
import com.taotao.pojo.TbContentCategory;
import com.taotao.pojo.TbContentCategoryExample;
import com.taotao.service.ContentCategoryService;
@Service
public class ContentCategoryServiceImpl implements ContentCategoryService {
@Autowired
private TbContentCategoryMapper tbContentCategoryMapper;
	@Override
	public List<TbContentCategory> getContentCategoryList(long parentId) {
		TbContentCategoryExample example =new TbContentCategoryExample();
		example.createCriteria().andParentIdEqualTo(parentId);
		return tbContentCategoryMapper.selectByExample(example);
	}
	@Override
	public TaotaoResult insertContentCategory(long parentId, String name) {
		TbContentCategory tcc=new TbContentCategory();
		tcc.setParentId(parentId);
		tcc.setName(name);
		tcc.setIsParent(false);
		tcc.setSortOrder(1);
		tcc.setStatus(1);
		tcc.setCreated(new Date());
		tcc.setUpdated(new Date());
		tbContentCategoryMapper.insert(tcc);
		TbContentCategory parent=tbContentCategoryMapper.selectByPrimaryKey(parentId);
		if(!parent.getIsParent()){
			parent.setIsParent(true);
			tbContentCategoryMapper.updateByPrimaryKey(parent);
		}
		return TaotaoResult.ok(tcc);
	}

}
